<template>
    <div class="page" >
        <div class="fullPageEdit">
            <div class="pan" style="width:720px">
                <div class="panHeader">
                    <div class="title"><i class="fa fa-cube"></i>赛事信息</div>
                    <div class="acs">
                        <ul class="lstPanAcs">
                            <li>
                                <div class="acBtn" @click="saveGameInfo()">
                                    <i class="fa fa-save"></i> 保存
                                </div>
                            </li>
                            <li>
                                <div class="acBtn" @click="refresh()">
                                    <i class="fa fa-reply"></i> 取消
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="panBody">
                    <div class="formEditPan">
                        <div class="editRow">
                            <div class="lab">name</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.name"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">localName</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.localName"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">shortName</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.shortName"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">localShortName</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.localShortName"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">primary</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.primary"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">responsible</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.responsible"></el-input>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">assistance</div>
                            <div class="edit">
                                <el-input v-model="gameInfo.assistance"></el-input>
                            </div>
                        </div> 
                        <div class="editRow">
                            <div class="lab">openDate</div>
                            <div class="edit">
                                <el-date-picker
                                    v-model="gameInfo.openDate"
                                    type="date"
                                    placeholder="选择日期">
                                </el-date-picker>
                            </div>
                        </div>
                        <div class="editRow">
                            <div class="lab">closeDate</div>
                            <div class="edit">
                                <el-date-picker
                                    v-model="gameInfo.closeDate"
                                    type="date"
                                    placeholder="选择日期">
                                </el-date-picker>
                            </div>
                        </div>
                    </div>

                </div>
            </div> 
        </div> 
    </div>
</template>

<script>
    export default {
        mounted() {
            var me = this;
            try{
                me.init();
            } catch(er){
                console.log(er);
            }
        },
        data() {
            return {
                gameInfo:{
                    assistance:"" , 
                    closeDate:"" , 
                    gameId:0 , 
                    localName:"" , 
                    localShortName:"" , 
                    name:"" , 
                    openDate:"" , 
                    primary:"" , 
                    responsible:"" , 
                    shortName:"" , 
                }
            };
        },
        methods: {
            init() {
                var me = this;
                try{
                    me.refresh().then(_=>{
                        var flag = me.gameInfo && me.gameInfo.gameId && me.gameInfo.gameId>0
                        if (!flag){
                            var key = "squ/baseData/gameInfo/createGameInfo";
                            var ps = { 
                                localName:"--" ,  
                                name:"-" ,  
                            };                            
                            me.sys.query(key, ps).then(res=>{
                                me.refresh();
                            })
                        }
                    })
                } catch(er){
                    console.log(er);
                }
            },
            saveGameInfo() {
                var me = this;
                try{
                    var gameInfo = JSON.parse(JSON.stringify( me.gameInfo));
                    if( gameInfo.openDate==null){}
                        gameInfo.openDate = ( new Date()).Format("yyyy-MM-dd");
                    var key = "squ/baseData/gameInfo/updateGameInfo";                         
                    me.sys.query(key, gameInfo).then(res=>{
                        if( res.rowcount && res.rowcount>0){
                            me.$message({
                                message: 'save game information success.',
                                type: 'success'
                            });
                            me.refresh();
                        }
                        else{
                            me.$message.error('save game information faild!');
                        }
                    })
                    
                } catch(er){
                    console.log(er);
                }
            },
            refresh() {
                var me = this;
                return new Promise( (success , faild )=>{
                    try{
                        var key = "squ/baseData/gameInfo/getGameInfo";
                        var ps = {};                            
                        me.sys.query(key, ps).then(res=>{
                            if( res && res.length>0){
                                me.gameInfo = res[0];
                            }
                            success();
                        })
                    } catch(er){
                        console.log(er);
                        success();
                    }
                })
            },
        },
        
    }
</script> 

<style lang="less" scoped>
    @import url('../module.less');
</style>